<template>
  <div class="app">
    <div class="result-div">
      <div v-if="passed" v-cloak>
        <div class="showGif">
          <img
            src="@/assets/img/success1.gif"
            class="imageShow"
            alt=""
            style="vertical-align: middle"
          />
        </div>
        <!--        <div>恭喜您，闯关成功！</div>-->
        <div class="opt-div">
          <el-button-group>
            <el-button size="small" type="danger" @click="back">返回上级</el-button>
          </el-button-group>
        </div>
      </div>
      <div v-if="unpassed" v-cloak>
        <div class="showGif">
          <img
            src="@/assets/img/fail.gif"
            class="imageShow"
            alt=""
            style="vertical-align: middle"
          />
        </div>
        <div class="opt-div">
          <el-button-group>
            <el-button size="small" type="primary" @click="toExamView">再考一次</el-button>
            <el-button size="small" type="danger" @click="back">返回上级</el-button>
          </el-button-group>
        </div>
      </div>
    </div>
    <!-- <div class="return" @click="back"></div>-->
  </div>
</template>

<script>
import { BizExamController } from '@/api';
export default {
  name: 'examResult',
  data() {
    return {
      sceneType: null,
      personnelType: null,
      moduleType: null,
      examLevel: 0,
      passed: false,
      unpassed: false
    };
  },
  methods: {
    back() {
      if (this.moduleType === 2) {
        this.$router.replace({
          name: 'frontScene',
          query: { sceneType: this.sceneType, personnelType: this.personnelType }
        });
      } else if (this.moduleType === 3) {
        this.$router.replace({
          name: 'frontExam',
          query: { sceneType: this.sceneType, personnelType: this.personnelType }
        });
      }
    },
    getRecord() {
      let params = {
        sceneType: this.sceneType,
        moduleType: this.moduleType,
        examLevel: this.examLevel
      };
      BizExamController.exist(this, params)
        .then(res => {
          if (res.data && res.data.passAble) {
            this.passed = true;
          } else {
            this.unpassed = true;
          }
        })
        .catch(e => {
          console.error(e);
        });
    },
    toExamView() {
      let params = {
        sceneType: this.sceneType,
        moduleType: this.moduleType,
        examLevel: this.examLevel
      };
      BizExamController.exist(this, params)
        .then(res => {
          if (res.data && res.data.passAble) {
            this.$router.replace({
              name: 'examresult',
              query: {
                sceneType: this.sceneType,
                moduleType: this.moduleType,
                personnelType: this.personnelType,
                examLevel: this.examLevel
              }
            });
          } else {
            this.$router.replace({
              name: 'examview',
              query: {
                sceneType: this.sceneType,
                moduleType: this.moduleType,
                personnelType: this.personnelType,
                examLevel: this.examLevel
              }
            });
          }
        })
        .catch(e => {
          console.error(e);
        });
    }
  },
  mounted() {
    const sceneType = this.$route.query.sceneType;
    this.sceneType = sceneType;
    const personnelType = this.$route.query.personnelType;
    this.personnelType = personnelType;
    const moduleType = this.$route.query.moduleType;
    this.moduleType = moduleType;
    const examLevel = this.$route.query.examLevel;
    this.examLevel = examLevel;
    this.getRecord();
  }
};
</script>

<style type="text/css" scoped>
.app {
  background-image: url('~@/assets/img/bg.png');
  background-size: cover;
  display: flex;
  justify-content: center; /* 水平居中 */
  align-items: center; /* 垂直居中 */
  height: 100vh; /* 让父容器充满整个视口高度 */
}

.result-div {
  width: 70%;
  height: 65%;
  display: flex;
  justify-content: center; /* 水平居中 */
  align-items: center; /* 垂直居中 */
  background: rgba(63, 212, 255, 0.04);
  box-shadow: inset 0px 0px 50px 20px rgba(28, 131, 193, 0.15);
  border-radius: 2px;
  border: 1px solid rgba(63, 212, 255, 0.24);
  font-family: 'Helvetica Neue', Helvetica, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei',
    '微软雅黑', Arial, sans-serif;
  font-style: italic;
  letter-spacing: 2px;
  font-size: 36px;
  color: #e3f3ff;
  line-height: 28px;
  letter-spacing: 1px;
  text-align: left;
  font-style: normal;
  padding: 35px;
  overflow-y: auto;
}

.opt-div {
  margin-top: 30px;
  display: flex;
  justify-content: center; /* 水平居中 */
  align-items: center; /* 垂直居中 */
}

.return {
  width: 252px;
  height: 66px;
  background-image: url('~@/assets/img/return.png');
  background-size: cover;
  position: absolute;
  bottom: 90px;
  cursor: pointer;
}

.showGif {
  display: flex;
  justify-content: center; /* 水平居中 */
  align-items: center; /* 垂直居中 */
}
.imageShow {
  width: 250px;
}
</style>
